package tagdb.util;

import tagdb.fragmentation.SpectrumPeak;
import tagdb.io.MascotGenericFile;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Helper class for spectrum conversions.
 *
 * @author Thilo Muth
 */
public class SpectrumUtils {

    /**
     * Converts the spectrum native peaks to a list of SpectrumPeak objects.
     * @param spectrum Input spectrum
     * @return the peak list
     */
    public static List<SpectrumPeak> getPeakListFromSpectrum(MascotGenericFile spectrum)   {
        Map<Double, Double> expPeaks = spectrum.getPeaks();
        Set<Map.Entry<Double, Double>> set = expPeaks.entrySet();
        List<SpectrumPeak> peakList = new ArrayList<SpectrumPeak>();

        for (Map.Entry<Double, Double> e : set) {
            peakList.add(new SpectrumPeak(e.getKey(), e.getValue()));
        }
        return peakList;
    }
}
